package com.newear.base.glide;

import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.module.GlideModule;

/**
 * Created by josan on 2016/8/13.
 * 自定义的GlideModule
 */
public class MyGlideModule implements GlideModule{
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        //设置内存缓存大小
        int maxMemory = (int) Runtime.getRuntime().maxMemory();
        int memoryCacheSize = maxMemory / 8;
        builder.setMemoryCache(new LruResourceCache(memoryCacheSize));

        //设置磁盘缓存
        String cacheDir = context.getExternalCacheDir() + "/image_cache";
        int diskCacheSize = 100 * 1024 * 1024;
        builder.setDiskCache(new DiskLruCacheFactory(cacheDir, "glide", diskCacheSize));
    }

    @Override
    public void registerComponents(Context context, Glide glide) {

    }
}
